<template>
	<view v-if="pageShow">
		<view class="" style="padding-bottom: 100rpx;">
			<!-- 轮播图 -->
			<view class="dingwei" v-if="dataAll.images_text">
				<u-swiper :list="dataAll.images_text" circular radius="0" height="290px"></u-swiper>
				<view class="flexleft icowz">
					<u-icon name="star" size="26" color="#f5f5f5" v-if="dataAll.is_sc==0" @click="collect()"></u-icon>
					<u-icon name="star-fill" size="26" color="#ffa126" v-if="dataAll.is_sc==1"
						@click="collect()"></u-icon>
					<!-- #ifdef MP-WEIXIN -->
					<button open-type="share">
						<u-icon name="share-square" size="26" color="#f5f5f5"></u-icon>
					</button>
					<!-- #endif -->
					<!-- #ifdef APP-PLUS -->
					<u-icon name="share-square" size="26" color="#f5f5f5"  @click="sharePoster()" ></u-icon>
					<!-- #endif -->
				</view>
			</view>
			<view class="mainpadding ffffff">
				<view class="sanshier xiaohei fonweight">{{dataAll.name}}</view>
				<view class="margin_top flexbetween">
					<view class="">
						<text class="xiaohong titletext fonweight margin_right1">￥{{dataAll.price}}
						</text>
						<text class="xiaohui zhonghuax ershiba">￥{{dataAll.yj_price}}</text>
					</view>
					<view class="xiaohui ershiba">库存：{{dataAll.stock}}</view>
				</view>
			</view>
			<!-- 课程详情 -->
			<view class="mainpadding ffffff margin_top1">
				<view class="sanshier xiaohei fonweight">散场详情</view>
				<view class="margin_top2 ">
					<image class="cgtpiam" v-for="(item,index) in dataAll.content_images_text" :key="index"
						@click="lbtpriview(index,dataAll.content_images_text)" :src="item" mode="widthFix"></image>
				</view>
			</view>
		</view>
		<!-- 固定底部 -->
		<view class="gudingdb">
			<view class="mainpadding ffffff flexbetween">
				<view class="strongtext xiaohei nofonweight">需支付：
					<text class="xiaohong ershiba fonweight margin_right1">￥{{dataAll.price}}
					</text>
				</view>
				<view class="xiaobtnty" @click="tzgoum(listid,dataAll.user_zbfapply_id)">立即预定</view>
			</view>
		</view>
		<zhangyu-qrcode-poster ref="poster" :title="dataAll.name" :headerImg="dataAll.image_text"
			price=""></zhangyu-qrcode-poster>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				listid: "",
				pageShow: false,
				dataAll: {},
				ewmimg:"",
				userInfo:{}
			}
		},
		onLoad(options) {
			if(options.id){
				this.listid = options.id
			}
			if (options.rec_user_id) {
				uni.setStorageSync("rec_user_id", options.rec_user_id)
			}
			// #ifdef MP-WEIXIN
			let _this = this
			const url = decodeURIComponent(options.q) // 获取到二维码原始链接内容
			if (url.indexOf("?") != -1) {
				var str = url.substr(url.indexOf("?") + 1);
				var strs = str.split("&");
				let theRequest = {};
				for (var i = 0; i < strs.length; i++) {
					theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]); 
				}
				console.log(theRequest,"二维码接收的参数");
				this.listid = options.id ? options.id : (theRequest.id ? theRequest.id :
					0);
				let rec_user_id = options.rec_user_id ? options.rec_user_id : (theRequest.rec_user_id ? theRequest.rec_user_id :
					0);
				if (rec_user_id != 0) {
					uni.setStorageSync('rec_user_id', rec_user_id);
				}
			}
			// #endif
			
			this.getDetail()
			// #ifdef APP-PLUS
			this.getewm()
			// #endif
		},
		// #ifdef MP-WEIXIN
		onShareAppMessage() {
			let _this = this
			return {
				title: this.dataAll.name,
				path: "pages_homepage/sanshangxq?id=" + this.listid + "&rec_user_id=" + uni.getStorageSync("user_id"),
			}
		},
		// #endif
		onShow() {
			if (httpRequest.checkIsLogin()) {
				this.userinfomsg()
			}
		},
		methods: {
			userinfomsg() {
				httpRequest.request('/api/user/index', 'GET', {}).then(res => {
					this.userInfo = res.data
				})
			},
			returnrztext(data){
				if(!data){
					return "未认证"
				}
				// 实名认证状态:1=待审核,2=认证成功,3=认证失败
				if(data.smrz_status==1){
					return "待审核"
				}else if(data.smrz_status==2){
					return "认证成功"
				}else if(data.smrz_status==3){
					return "认证失败"
				}
			},
			getewm() {
				httpRequest.request("/api/user/getCodeImage", 'GET', {
					type_id: this.listid,
					type: 2 //1=场地,2=课程,3=赛事,4=活动,5=商城
				}, false, false, true).then(res => {
					this.ewmimg = res.data.code_image
				})
			},
			sharePoster() {
				//获取带参数二维码
				this.$refs.poster.showCanvas(this.ewmimg)
			},
			jumpurl(url, id) {
				uni.navigateTo({
					url: url + id
				})
			},
			phone(p) {
				uni.makePhoneCall({
					phoneNumber: p.toString()
				}).catch((e) => {
					// console.log(e)  //用catch(e)来捕获错误{makePhoneCall:fail cancel}
				})
			},
			collect() {
				httpRequest.request('/api/kccl/kcCollect', 'GET', {
					kc_id: this.listid
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						this.dataAll.is_sc = this.dataAll.is_sc == 1 ? 0 : 1
					}
				})
			},
			lbtpriview(index, arr) {
				var i = arr; //获取当前页面的轮播图数据
				//uniapp预览轮播图
				uni.previewImage({
					current: index, //预览图片的下标
					urls: i //预览图片的地址，必须要数组形式，如果不是数组形式就转换成数组形式就可以
				})
			},
			getDetail() {
				httpRequest.request('/api/cgcl/cgScDetail', 'GET', {
					id: this.listid
				}, false, false, true).then(res => {
					this.dataAll = res.data
					this.pageShow = true
				})
			},
			// 跳转购买订单详情
			tzgoum(id,user_zbfapply_id) {
				
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return false
				}
				let smrzstatus = this.returnrztext(this.userInfo.usersmrz)
				if(smrzstatus=="未认证"){
					httpRequest.toast("请先实名认证")
					setTimeout(()=>{
						uni.navigateTo({
							url: '/pages_mypage/shengfenzrz'
						})
					},1000)
					return false
				}
				if(smrzstatus=="待审核"){
					httpRequest.toast("实名认证审核中，暂时无法购买散场")
					return false
				}
				if(smrzstatus=="认证失败"){
					httpRequest.toast("实名认证失败，请重新提交审核后再重新购买散场")
					setTimeout(()=>{
						uni.navigateTo({
							url: '/pages_mypage/shenhe'
						})
					},1000)
					return false
				}
				uni.navigateTo({
					url: '/pages_homepage/sanchangyd?id=' + id+"&user_zbfapply_listid="+user_zbfapply_id
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.xiaolvbtn {
		// width: 112rpx;
		padding: 15rpx 30rpx;
		// height: 56rpx;
		background: #1BA95B;
		border-radius: 32rpx 32rpx 32rpx 32rpx;
		font-size: 26rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.shilitu {
		width: 200rpx;
		height: 160rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.changdi {
		width: 100rpx;
		height: 100rpx;

		image {
			border-radius: 50%;
			width: 100%;
			height: 100%;
		}
	}

	.cgtpiam {
		width: 100%;
		border-radius: 16rpx;
	}

	.lvbox {
		padding: 24rpx 20rpx;
		background: #EFFFF6;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
	}

	page {
		background: #F9F9F9;
	}

	.icowz {
		position: absolute;
		top: 30rpx;
		right: 30rpx;
	}

	.guandys {
		position: absolute;
		right: 30rpx;
		top: 30rpx;
	}

	.bofang {
		width: 120rpx;
		height: 120rpx;
		background-size: 100% 100%;
		position: absolute;
		bottom: 222rpx;
		left: 316rpx;
		background-image: url('../static/image/system/bfh.png');
	}

	.erwim {
		width: 128rpx;
		height: 128rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.erwmtu {
		width: 412rpx;
		height: 328rpx;
		border-radius: 8rpx;

		image {
			border-radius: 8rpx;
			width: 100%;
			height: 100%;
		}
	}
</style>